{extend name="app/shop/view/base.html"/}
{block name="resources"}
<style>
	.ns-form-row{margin-top: 0;}
	.network-domain{
		margin:10px 0;
	}
	.add-domain{
		font-size: 22px;
		border: 1px solid #ff8143;
		border-radius: 50%;
		display: inline-block;
		height: 22px;
		line-height: 22px;
		text-align: center;
		width: 22px;
		cursor:pointer;
	}
	.del-domain{
		font-size:25px;
		color:red;
		border:1px solid red;
		border-radius:50%;
		display:inline-block;
		height:22px;
		line-height:19px;
		text-align:center;
		width:22px;
		cursor:pointer;
	}
</style>
{/block}
{block name="main"}
<div class="layui-form">
	<div class="layui-card ns-card-common ns-card-brief">
		<div class="layui-card-header">
			<span class="ns-card-title">微信小程序设置</span>
		</div>

		<div class="layui-card-body">
			<div class="layui-form-item">
				<label class="layui-form-label">小程序名称：</label>
				<div class="layui-input-block">
					<span class="open-text">{$config.value.nick_name ?? ''}</span>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">主体信息：</label>
				<div class="layui-input-block">
					<span class="open-text">{$config.value.principal_name ?? ''}</span>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">公众号类型：</label>
				<div class="layui-input-block">
					<span class="open-text">{$config.value.service_type_info ?? ''}</span>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">认证情况：</label>
				<div class="layui-input-block">
					<span class="open-text">{$config.value.verify_type_info ?? ''}</span>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">小程序授权状态：</label>
				<div class="layui-input-block">
					<span class="open-text">已授权&nbsp;&nbsp;&nbsp;<a class="ns-text-color" href="{:addon_url('wxoplatform://shop/oplatform/weappsettled')}">重新授权</a></span>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">小程序头像：</label>
				<div class="layui-input-block">
					<div class="upload-img-block square">
						<div class="upload-img-box">
							<img src="{:img($config.value.head_img)}"/>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">小程序二维码：</label>
				<div class="layui-input-block">
					<div class="upload-img-block square">
						<div class="upload-img-box">
							<img src="{:img($config.value.qrcode_url)}"/>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div class="layui-card ns-card-common ns-card-brief">
		<div class="layui-card-header">
			<span class="ns-card-title">开发者ID设置</span>
		</div>

		<div class="layui-card-body">
			<div class="layui-form-item">
				<label class="layui-form-label">APPID：</label>
				<div class="layui-input-block">
					<span class="open-text">{$config.value.authorizer_appid ?? ''}</span>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">原始ID：</label>
				<div class="layui-input-block">
					<span class="open-text">{$config.value.user_name ?? ''}</span>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">开放平台帐号ID：</label>
				<div class="layui-input-block">
					<span class="open-text">{$config.value.component_appid ?? ''}</span>
				</div>
			</div>
			
		</div>
	</div>

	<div class="layui-card ns-card-common ns-card-brief">
		<div class="layui-card-header">
			<span class="ns-card-title">服务器配置信息</span>
		</div>
		<div class="layui-card-body">
			<div class="layui-form-item">
				<label class="layui-form-label">request合法域名：</label>
				<div class="layui-input-block request-domain">
						{if empty($config.value.miniprograminfo.network.RequestDomain)}
							<div class="network-domain">
								<div class="layui-input-inline">
									<input type="text" name="RequestDomain[]" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="">
								</div>
								<i class="ns-text-color add-domain" type="RequestDomain">+</i>
							</div>
						{else/}
							{foreach $config.value.miniprograminfo.network.RequestDomain as $k => $v}
								<div class="network-domain">
									<div class="layui-input-inline">
									<input type="text" name="RequestDomain[]" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="{$v}">
									</div>
									{if $k == 0}
									<i class="ns-text-color add-domain" type="RequestDomain">+</i>
									{/if}
									{if $k != 0}
									<i class="del-domain">-</i>
									{/if}
								</div>
							{/foreach}
						{/if}
				</div>
				<div class="ns-word-aux">request合法域名以 https://开头，最多可以配置 200 个域名。</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">socket合法域名：</label>
				<div class="layui-input-block wsrequest-domain">

					{if empty($config.value.miniprograminfo.network.WsRequestDomain)}
					<div class="network-domain">
						<div class="layui-input-inline">
							<input type="text" name="WsRequestDomain[]" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="">
						</div>
						<i class="ns-text-color add-domain" type="WsRequestDomain">+</i>
					</div>
					{else/}
					{foreach $config.value.miniprograminfo.network.WsRequestDomain as $k => $v}
					<div class="network-domain">
						<div class="layui-input-inline">
							<input type="text" name="WsRequestDomain[]" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="{$v}">
						</div>
						{if $k == 0}
						<i class="ns-text-color add-domain" type="WsRequestDomain">+</i>
						{/if}
						{if $k != 0}
						<i class="del-domain">-</i>
						{/if}
					</div>
					{/foreach}
					{/if}
				</div>
				<div class="ns-word-aux">socket合法域名以 wss://开头，最多可以配置 200 个域名。</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">uploadFile合法域名：</label>
				<div class="layui-input-block upload-domain">
					{if empty($config.value.miniprograminfo.network.UploadDomain)}
					<div class="network-domain">
						<div class="layui-input-inline">
							<input type="text" name="UploadDomain[]" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="">
						</div>
						<i class="ns-text-color add-domain" type="UploadDomain">+</i>
						
					</div>
					{else/}
					{foreach $config.value.miniprograminfo.network.UploadDomain as $k => $v}
					<div class="network-domain">
						<div class="layui-input-inline">
							<input type="text" name="UploadDomain[]" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="{$v}">
						</div>
						{if $k == 0}
						<i class="ns-text-color add-domain" type="UploadDomain">+</i>
						{/if}
						{if $k != 0}
						<i class="del-domain">-</i>
						{/if}
					</div>
					{/foreach}
					{/if}
				</div>
				<div class="ns-word-aux">uploadFile合法域名以 https://开头，最多可以配置 200 个域名。</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">downloadFile合法域名：</label>
				<div class="layui-input-block download-domain">

					{if empty($config.value.miniprograminfo.network.DownloadDomain)}
					<div class="network-domain">
						<div class="layui-input-inline">
							<input type="text" name="DownloadDomain[]" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="">
						</div>
						<i class="ns-text-color add-domain" type="DownloadDomain">+</i>
						
					</div>
					{else/}
					{foreach $config.value.miniprograminfo.network.DownloadDomain as $k => $v}
					<div class="network-domain">
						<div class="layui-input-inline">
							<input type="text" name="DownloadDomain[]" lay-verify="required"  autocomplete="off" class="layui-input ns-len-long" value="{$v}">
						</div>
						{if $k == 0}
						<i class="ns-text-color add-domain" type="DownloadDomain">+</i>
						{/if}
						{if $k != 0}
						<i class="del-domain">-</i>
						{/if}
					</div>
					{/foreach}
					{/if}
				</div>
				<div class="ns-word-aux">downloadFile合法域名以 https://开头，最多可以配置 200 个域名。</div>

			</div>
		</div>
	</div>
	<div class="ns-single-filter-box">
		<div class="ns-form-row">
			<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
			<button type="reset" class="layui-btn layui-btn-primary" onclick="back()">返回</button>
		</div>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	layui.use(['form'], function () {
		var form = layui.form,
			repeat_flag = false; //防重复标识
		form.render();

		form.on('submit(save)', function (data) {
			if (repeat_flag) return;
			repeat_flag = true;
			$.ajax({
				type: "post",
				url: "{:addon_url('wxoplatform://shop/oplatform/weapp')}",
				dataType: "JSON",
				data: data.field,
				success: function (data) {
					repeat_flag = false;
					layer.msg(data.message);
				}
			});
		});
		
	});

	function back() {
		location.href = "{:addon_url('weapp://shop/weapp/setting')}";
	}

	//新增
	$('body').on('click', '.add-domain', function(){
		var type = $(this).attr('type');
		var html = `
				<div class="network-domain">
					<div class="layui-input-inline">
						<input type="text" name="${type}[]" lay-verify="required" autocomplete="off" class="layui-input ns-len-long" value="">
					</div>
					<i class="del-domain">-</i>
				</div>
`;
		var parent_obj = $(this).parent();
		parent_obj.after(html);
	});
	//删除
	$('body').on('click', '.del-domain', function(){
		$(this).parent().remove();
	})
</script>
{/block}